package com.example.demo.controller;

import com.example.demo.domain.AjaxResult;
import com.example.demo.utils.DateUtil;
import com.example.demo.utils.InterfaceUtil;
import com.ideabank.bean.TSAResult;
import com.ideabank.exception.TSAExcepption;
import com.ideabank.po.TSAInterface;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.Map;

@Controller
@RequestMapping("/testTSA")
public class TestTSAController {
    /**
     * 创建时间戳
     *
     * @param data
     * @return
     */
    @RequestMapping("/createTimestamp")
    @ResponseBody
    public AjaxResult createTimestamp(String data)  {
        AjaxResult ar = new AjaxResult();
        TSAInterface tsa = InterfaceUtil.getTSAInterface();
        if (tsa == null) {
            return AjaxResult.ERROR("初始化失败");
        }
        try {
            String result=tsa.createTimestamp(data);
            return AjaxResult.SUCCESS(result);
        } catch (TSAExcepption tsaExcepption) {
            tsaExcepption.printStackTrace();
            return AjaxResult.ERROR(tsaExcepption.getMessage());
        }
    }

    /**
     * 验证时间戳
     *
     * @return
     * @throws Exception
     */
    @RequestMapping("/verifyTimestamp")
    @ResponseBody
    public AjaxResult verifyTimestamp(String timeStamp) {
        TSAInterface tsa = InterfaceUtil.getTSAInterface();
        if (tsa == null) {
            return AjaxResult.ERROR("初始化失败");
        }
        try {
            TSAResult tsaResult = tsa.verifyTimestamp(timeStamp);
            return tsaResult.getStatus()? AjaxResult.SUCCESS("",tsaResult):AjaxResult.ERROR("验证时间戳失败");
        } catch (TSAExcepption tsaExcepption) {
            tsaExcepption.printStackTrace();
            return AjaxResult.ERROR(tsaExcepption.getMessage());
        }
    }

    /**
     * 解析时间戳
     *
     * @param timeStamp
     * @return
     * @throws Exception
     */
   /* @RequestMapping("/parseTimestamp")
    @ResponseBody
    public AjaxResult parseTimestamp(String timeStamp) {
        TSAInterface tsa = InterfaceUtil.getTSAInterface();
        if (tsa == null) {
            return AjaxResult.ERROR("初始化失败");
        }
        try{
        Map<String,String> map = tsa.parseTimestamp(timeStamp,0);
        return AjaxResult.SUCCESS(map.toString());
        } catch (NetonejExcepption netonejExcepption) {
            netonejExcepption.printStackTrace();
            return AjaxResult.ERROR(netonejExcepption.getMessage());
        }
    }*/


}
